package com.offcn.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.offcn.mapper.PermissionMapper;
import com.offcn.mapper.RoleMapper;
import com.offcn.mapper.UserMapper;
import com.offcn.pojo.Permission;
import com.offcn.pojo.Role;
import com.offcn.pojo.User;
import com.offcn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: wy
 * @Date: 2022/9/7 09:41
 */
@Service
@Component
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public List<Role> getRoleInfoByUid(Integer uid) {

        List<Role> roleInfoByUid = roleMapper.getRoleInfoByUid(uid);
        return roleInfoByUid;
    }


    /**
     * 根据用户id查询用户相关权限信息
     *
     * @param uid
     * @return
     */
    @Override
    public List<Permission> getPermissionByUid(Integer uid) {

        List<Permission> permissionByUid = permissionMapper.getPermissionByUid(uid);

        return permissionByUid;
    }

    @Override
    public User getOneUserByName(String name) {
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(User::getUsername, name);
        User user = userMapper.selectOne(userLambdaQueryWrapper);
        return user;
    }
}
